home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / hity wydania / Ubuntu 9.10 PL / karmelkowy-koliberek-desktop-9.10-i386-PL.iso / casper / filesystem.squashfs / var / lib / dpkg / info / samba-common.postinst < prev    next >
Text File  |  2009-10-29  |  4KB  |  142 lines

  1. #!/bin/sh
  2. #
  3. #
  4.  
  5. set -e
  6.  
  7. # Do debconf stuff here
  8. . /usr/share/debconf/confmodule
  9.  
  10. TEMPDIR=/var/run/samba/upgrades
  11. NEWFILE=$TEMPDIR/smb.conf
  12. CONFIG=/etc/samba/smb.conf
  13.  
  14. # ------------------------- Debconf questions start ---------------------
  15.  
  16. configure_smb_conf() {
  17.     local CONFIG
  18.     CONFIG="$1"
  19.  
  20.     # Is the user configuring with debconf, or he/she prefers
  21.     # swat/manual config?
  22.     db_get samba-common/do_debconf || true
  23.     if [ "${RET}" != "true" ]; then
  24.         return 0
  25.     fi
  26.  
  27.     # Get workgroup name
  28.     db_get samba-common/workgroup || true
  29.     WORKGROUP="${RET}"
  30.  
  31.     # Oh my GOD, this is ugly.  Why would anyone put these
  32.     # characters in a workgroup name?  Why, Lord, why???
  33.     WORKGROUP=`echo $WORKGROUP | \
  34.                sed -e's/\\\\/\\\\\\\\/g
  35.                       s#/#\\\\/#g
  36.                       s/&/\\\&/g
  37.                       s/\\\$/\\\\\\\$/g'`
  38.  
  39.     sed -i -e "s/^\([[:space:]]*\)\[global\]/\1\[global\]/i
  40.         /^[[:space:]]*\[global\]/,/^[[:space:]]*\[/ \
  41.             s/^\([[:space:]]*\)workgroup[[:space:]]*=.*/\1workgroup = ${WORKGROUP}/i" \
  42.         "$CONFIG"
  43.  
  44.     # Encrypt passwords?
  45.     db_get samba-common/encrypt_passwords || true
  46.     ENCRYPT_PASSWORDS="${RET}"
  47.  
  48.     sed -i -e "s/^\([[:space:]]*\)\[global\]/\1\[global\]/i
  49.         /^[[:space:]]*\[global\]/,/^[[:space:]]*\[/ \
  50.                 s/^\([[:space:]]*\)encrypt passwords[[:space:]]*=.*/\1encrypt passwords = ${ENCRYPT_PASSWORDS}/i" \
  51.         "$CONFIG"
  52.  
  53.     # Install DHCP support
  54.     db_get samba-common/dhcp
  55.     if [ "$RET" = true ] && \
  56.        ! grep -q dhcp.conf "$CONFIG"
  57.     then
  58.         sed -i -e "s/^\([[:space:]]*\)\[global\]/\1\[global\]/i
  59.             /^[[:space:]]*\[global\]/,/^[[:space:]]*\[/ {
  60.                 /wins server[[:space:]]*=/a \\
  61. \\
  62. # If we receive WINS server info from DHCP, override the options above. \\
  63.    include = /etc/samba/dhcp.conf
  64. }" "$CONFIG"
  65.     elif [ "$RET" != true ]; then
  66.         sed -i -e '
  67.         /^#[[:space:]]*If we receive WINS server info from DHCP, override the options above/d
  68.         /^#*[[:space:]]*include[[:space:]]*=[[:space:]]*\/etc\/samba\/dhcp.conf/,/[^[:space:]]/ {
  69.             /^#*[[:space:]]*include[[:space:]]*=[[:space:]]*\/etc\/samba\/dhcp.conf/d
  70.             /^[[:space:]]*$/d
  71.         }' "$CONFIG"
  72.     fi
  73.  
  74.     if [ -n "$2" ] && dpkg --compare-versions "$2" lt 3.0.23b-2 \
  75.        && grep -qi "^[[:space:]]*passdb backend[[:space:]]*=.*guest" "$CONFIG"
  76.     then
  77.         sed -i -e "s/^\([[:space:]]*\)\[global\]/\1\[global\]/i
  78.             /^[[:space:]]*\[global\]/,/^[[:space:]]*\[/ \
  79.                     s/^\([[:space:]]*passdb backend[[:space:]]*=[^,]*\),\?[[:space:]]*guest[[:space:]]*$/\1/i" \
  80.             "$CONFIG"
  81.     fi
  82. }
  83.  
  84.  
  85. if [ -e "$CONFIG" ]; then
  86.     configure_smb_conf "$CONFIG"
  87. fi
  88.  
  89. mkdir -p "$TEMPDIR"
  90.  
  91. if [ -n "$2" ] && dpkg --compare-versions "$2" lt 3.0.28-3; then
  92.     if dpkg --compare-versions "$2" lt 3.0.26a-1 && [ "$2" != "${2%ubuntu*}" ]
  93.     then
  94.         base=dapper
  95.     elif [ "$2" != "${2%ubuntu*}" ]
  96.     then
  97.         base=gutsy
  98.     else
  99.         base=etch
  100.     fi
  101.  
  102.     TEMPLATE=/usr/share/samba/smb.conf.${base}
  103.  
  104.     cp "$TEMPLATE" "$NEWFILE"
  105.     configure_smb_conf "$NEWFILE"
  106.  
  107.     if [ -e "$CONFIG" ]; then
  108.         sed -e '1,/^[;#[:space:]]*\[cdrom\]/ { d }
  109.             1,/^[[:space:]]*\[/ { /^[^[]/d; /^$/d }
  110.         ' "$CONFIG" >> "$NEWFILE"
  111.     fi
  112.  
  113.     ucf --three-way --debconf-ok "$NEWFILE" "$CONFIG"
  114. fi
  115.  
  116. cp /usr/share/samba/smb.conf "$NEWFILE"
  117. configure_smb_conf "$NEWFILE"
  118.  
  119. if [ -e "$CONFIG" ]; then
  120.     sed -e '1,/^[;#[:space:]]*\[cdrom\]/ { d }
  121.         1,/^[[:space:]]*\[/ { /^[^[]/d; /^$/d }
  122.     ' "$CONFIG" >> "$NEWFILE"
  123. fi
  124.  
  125. ucf --three-way --debconf-ok "$NEWFILE" "$CONFIG"
  126.  
  127. if [ ! -e "$CONFIG" ]; then
  128.     echo "Install/upgrade will fail. To recover, please try:"
  129.     echo "  sudo cp /usr/share/samba/smb.conf $CONFIG"
  130.     echo "  sudo dpkg --configure -a"
  131.     exit 1
  132. else
  133.     ucfr samba-common "$CONFIG"
  134.     chmod a+r "$CONFIG"
  135. fi
  136.  
  137. # ------------------------- Debconf questions end ---------------------
  138.  
  139. db_stop
  140.  
  141.  
  142.